package nio.engine;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import nio.engine.DeliverCallback;
import nio.engine.NioChannel;
import nio.engine.NioEngine;


public class NioChannelClass extends NioChannel{
	
	// Connection 
	private SocketChannel channel;
	private NioChannelClass nioEngine;
	private DeliverCallback deliverCallback;	

	// ByteBuffer for write/read
	private ByteBuffer writeBuffer;
	private ByteBuffer writeLength;
	private ByteBuffer readBuffer;
	private ByteBuffer readLength;

	public SocketChannel getChannel() {
		
		return channel ;
	}

	@Override
	public void setDeliverCallback(DeliverCallback callback) {
		this.deliverCallback = callback;		
	}

	@Override
	// A completer 
	public InetSocketAddress getRemoteAddress() {
		InetSocketAddress adress = null ;
		try {
			//adress = (InetSocketAddress) channel.getRemoteAddress();		}
	}

	@Override
	// A completer 

	public void send(ByteBuffer buf) {
		
		
	}

	@Override
	// A completer 

	public void send(byte[] bytes, int offset, int length) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void close() {
		try{
			channel.close();
		} catch (IOException e) {
			System.out.println("The channel is already closed");
		}	
		//Panic? we will see 
		//channel.keyFor(this.nioEngine.getSelector()).cancel();
	}
	
}
